﻿using DevExpress.XtraEditors;
using DLL;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NursingFormSystem
{
    public partial class AddEduProject : Form
    {
        public string sql = "";
        public string ProjectGuid = "";
        public string ClassGuid = "";
        public AddEduProject(string projectguid, string classguid)
        {
            InitializeComponent();
            Text = "项目管理";
            if (projectguid == "-1")
            {
                Text = "新增项目";
                ClassGuid = classguid;
                sql = @"insert  into [BNNursingDocsSystem_Develop].[dbo].[HealthEduProject]  (ProjectName,ClassGuid,ProjectGuid,OrderNum) values ";
            }
            else
            {
                Text = "修改项目";
                ProjectGuid = projectguid;
                sql = @"SELECT * FROM [BNNursingDocsSystem_Develop].[dbo].[HealthEduProject](NOLOCK) where ProjectGuid ='" + ProjectGuid + "'";
                DataTable Class = SqlHelper.ExecuteDataset(sql, CommandType.Text).Tables[0];
                textEdit1.Text = Class.Rows[0]["ProjectName"].ToString();
                textEdit2.Text = Class.Rows[0]["OrderNum"].ToString();
                sql = @"update  [BNNursingDocsSystem_Develop].[dbo].[HealthEduClass]  set ";
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {

            DialogResult = System.Windows.Forms.DialogResult.No;
            Close();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.OK;
            if (Text == "新增项目")
            {
                sql += @" ('" + textEdit1.Text + "','" + ClassGuid + "','" + Guid.NewGuid().ToString() + "','" + textEdit2.Text + "')";
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql);
                XtraMessageBox.Show("新增成功!");
                Close();
            }
            else
            {
                sql += @"ProjectName ='" + textEdit1.Text + "' , OrderNum ='" + textEdit2.Text + "' where ProjectGuid = '" + ClassGuid + "'";
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql);
                XtraMessageBox.Show("修改成功!");
                Close();
            }
        }
       
    }
}
